package main

import (
	. "com/aip"
	. "fmt"
	"strconv"
)

func main() {

	Println("operate\t\t\tlen\tpos\tsize")
	Println("================================================:W")

	var bin *ByteCool = NewByteCool(0)

	var i8 int8 = 127
	bin.WriteInt8(i8)
	Printf("%s:%d\t\t\t%d\t%d\t%d\n", "wI8", i8, bin.GetLength(), bin.GetPosition(), bin.GetSize())

	var u8 byte = 254
	bin.WriteUint8(u8)
	Printf("%s:%d\t\t\t%d\t%d\t%d\n", "wU8", u8, bin.GetLength(), bin.GetPosition(), bin.GetSize())

	var i16 int16 = 32766
	bin.WriteInt16(i16)
	Printf("%s:%d\t\t%d\t%d\t%d\n", "wI16", i16, bin.GetLength(), bin.GetPosition(), bin.GetSize())

	var u16 uint16 = 65533
	bin.WriteUint16(u16)
	Printf("%s:%d\t\t%d\t%d\t%d\n", "wU16", u16, bin.GetLength(), bin.GetPosition(), bin.GetSize())

	var i32 int32 = -2147483644
	bin.WriteInt32(i32)
	Printf("%s:%d\t%d\t%d\t%d\n", "wI32", i32, bin.GetLength(), bin.GetPosition(), bin.GetSize())

	var u32 uint32 = 2147483642
	bin.WriteUint32(u32)
	Printf("%s:%d\t\t%d\t%d\t%d\n", "wU32", u32, bin.GetLength(), bin.GetPosition(), bin.GetSize())

	//float f32 = (float)3.40282e+038;
	//float f32 = (float)-3.40282e+038;
	var f32 float32 = 123.456
	bin.WriteFloat32(f32)
	Printf("%s:%f\t\t%d\t%d\t%d\n", "wF32", f32, bin.GetLength(), bin.GetPosition(), bin.GetSize())

	//double f64 = 1.79769e+308;
	//double f64 = -1.79769e+308;
	var f64 float64 = 456.78901234
	bin.WriteFloat64(f64)
	Printf("%s:%f\t\t%d\t%d\t%d\n", "wF64", f64, bin.GetLength(), bin.GetPosition(), bin.GetSize())

	Println("================================================:R")
	Printf("%s:%d\t\t\t%d\t%d\t%d\n", "rI8", bin.ReadInt8(), bin.GetLength(), bin.GetPosition(), bin.GetSize())

	Printf("%s:%d\t\t\t%d\t%d\t%d\n", "rU8", bin.ReadUint8(), bin.GetLength(), bin.GetPosition(), bin.GetSize())

	Printf("%s:%d\t\t%d\t%d\t%d\n", "rI16", bin.ReadInt16(), bin.GetLength(), bin.GetPosition(), bin.GetSize())

	Printf("%s:%d\t\t%d\t%d\t%d\n", "rU16", bin.ReadUint16(), bin.GetLength(), bin.GetPosition(), bin.GetSize())

	Printf("%s:%d\t%d\t%d\t%d\n", "rI32", bin.ReadInt32(), bin.GetLength(), bin.GetPosition(), bin.GetSize())

	Printf("%s:%d\t\t%d\t%d\t%d\n", "rU32", bin.ReadUint32(), bin.GetLength(), bin.GetPosition(), bin.GetSize())

	Printf("%s:%f\t\t%d\t%d\t%d\n", "rF32", bin.ReadFloat32(), bin.GetLength(), bin.GetPosition(), bin.GetSize())

	Printf("%s:%f\t\t%d\t%d\t%d\n", "rF64", bin.ReadFloat64(), bin.GetLength(), bin.GetPosition(), bin.GetSize())

	Println("================================================:abbr")
	Printf("r:%d\n", bin.GetBytesReadable())
	Printf("w:%d\n", bin.GetBytesWriteable())

	Println("================================================:bin/str")

	var data *ByteCool = NewByteCool(3)
	data.WriteInt8(11)
	data.WriteInt8(22)
	data.WriteInt8(33)

	var bytes []byte = []byte{101, 102, 103}

	bin.WriteBin(data)
	Printf("%s:%d\t%d\t%d\t%d\n", "wByteArray(len)", data.GetLength(), bin.GetLength(), bin.GetPosition(), bin.GetSize())
	var tmpA *ByteCool = bin.ReadBin(3)
	Printf("%s:%s\t%d\t%d\t%d\n", "rByteArray", strconv.Itoa(int(tmpA.ReadInt8()))+","+strconv.Itoa(int(tmpA.ReadInt8()))+","+strconv.Itoa(int(tmpA.ReadInt8())), bin.GetLength(), bin.GetPosition(), bin.GetSize())

	bin.WriteBytes(bytes)
	Printf("%s:%d\t\t%d\t%d\t%d\n", "wBytes(len)", len(bytes), bin.GetLength(), bin.GetPosition(), bin.GetSize())
	var tmpB []byte = bin.ReadBytes(len(bytes))
	Printf("%s:%s\t%d\t%d\t%d\n", "rBytes", strconv.Itoa(int(tmpB[0]))+","+strconv.Itoa(int(tmpB[1]))+","+strconv.Itoa(int(tmpB[2])), bin.GetLength(), bin.GetPosition(), bin.GetSize())

	var str string = "hello"
	bin.WriteUTF8(str)
	Printf("%s:%s\t\t%d\t%d\t%d\n", "wString", str, bin.GetLength(), bin.GetPosition(), bin.GetSize())
	Printf("%s:%s\t\t%d\t%d\t%d\n", "rString", bin.ReadUTF8(len(str)), bin.GetLength(), bin.GetPosition(), bin.GetSize())

	var strB string = " world !"
	bin.WriteLenUTF8(strB)
	Printf("%s:%s\t%d\t%d\t%d\n", "wLenStr", strB, bin.GetLength(), bin.GetPosition(), bin.GetSize())
	Printf("%s:%s\t%d\t%d\t%d\n", "rLenStr", bin.ReadLenUTF8(), bin.GetLength(), bin.GetPosition(), bin.GetSize())

	bin.WriteLenBytes(bytes)
	var tmpC []byte = bin.ReadLenBytes()
	Printf("%s:%d\t%d\t%d\t%d\n", "wLenBytes(len)", len(bytes), bin.GetLength(), bin.GetPosition(), bin.GetSize())
	Printf("%s:%s\t%d\t%d\t%d\n", "rLenBytes", strconv.Itoa(int(tmpC[0]))+","+strconv.Itoa(int(tmpC[1]))+","+strconv.Itoa(int(tmpC[2])), bin.GetLength(), bin.GetPosition(), bin.GetSize())

	var clone *ByteCool = bin.Clone(false)
	Printf("%s:%d\t\t%d\t%d\t%d\n", "cloneF", clone.ReadInt8(), clone.GetLength(), clone.GetPosition(), clone.GetSize())

	var cloneB *ByteCool = bin.Clone(true)
	Printf("%s:%d\t\t%d\t%d\t%d\n", "cloneT", cloneB.ReadInt8(), cloneB.GetLength(), cloneB.GetPosition(), cloneB.GetSize())

	var input string
	Scanln(&input)

}
